package com.djq.hhc.config;

import com.djq.hhc.interceptor.AdminInterceptor;
import com.djq.hhc.interceptor.LoginInterceptor;
import com.djq.hhc.interceptor.RefreshInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: dadd7
 * @Date: 2023/03/06/下午 6:57
 * @Description:
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new RefreshInterceptor(stringRedisTemplate))
                .addPathPatterns("/**").order(1);
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns(
                        "/credit/**",//积分拦截
                        "/home/homeFamily/save",
                        "/home/homeFamily/update",
                        "/home/homeFamily/remove/{id}",
                        "/home/homeFlower/save",
                        "/home/homeFlower/update",
                        "/home/homeFlower/remove/{id}",
                        "/post/postInfo/likes/{id}",
                        "/post/postInfo/post",
                        "/post/postInfo/remove/{id}",
                        "/post/postInfo/update",
                        "/post/postType/save",
                        "/post/postType/remove/{id}",
                        "/post/postType/update",
                        "/shop/shopGoods/buyGoods/{id}",
                        "/shop/shopGoods/update",
                        "/shop/shopGoods/remove/{id}",
                        "/shop/shopGoods/save",
                        "/shop/shopOrder/**",
                        "/user/userFollow/**",
                        "/user/userInfo/getNowUserWithCredit",
                        "/user/userInfo/updateNowUser",
                        "/user/userInfo/logout",
                        "/user/userInfo/findAll",
                        "/user/userInfo/save",
                        "/user/userInfo/update",
                        "/user/userInfo/remove/{id}",
                        "/user/userInfo/batchRemove",
                        "/user/userInfo/getLoginUser"
//                        "/user/userInfo/{page}/{limit}"
                ).order(2);
        registry.addInterceptor(new AdminInterceptor())
                .addPathPatterns(
                        "/home/homeFamily/save",
                        "/home/homeFamily/update",
                        "/home/homeFamily/remove/{id}",
                        "/home/homeFlower/save",
                        "/home/homeFlower/update",
                        "/home/homeFlower/remove/{id}",

                        "/post/postInfo/remove/{id}",
                        "/post/postInfo/update",
                        "/post/postType/save",
                        "/post/postType/remove/{id}",
                        "/post/postType/update",

                        "/shop/shopGoods/update",
                        "/shop/shopGoods/remove/{id}",
                        "/shop/shopGoods/save",

//                        "/user/userInfo/{page}/{limit}",
                        "/user/userInfo/findAll",
                        "/user/userInfo/save",
                        "/user/userInfo/remove/{id}",
                        "/user/userInfo/batchRemove"
                ).order(3);
    }
}

